<?
##########################################################################
#		DOCUMENTATION
##########################################################################
# Class that extends the rootclass. This module is "what have in common" the
# category and topviewed pages. 
#
# © LiberLab group, 2011
##########################################################################

require_once("baseList.php");

abstract class BaseCatTop extends BaseList{
	# use parent constructor
	
	public function main(){
		$numBooks = 0;
		
		$viewsData = $this->getViewesAndBox();
		$views = $viewsData["views"]; $topViewedBox = $viewsData["topViewedBox"];

		$numBooks = count($views);

		$this->tagHash["imgLinkINDEX§§§§topViewedCoverINDEX§§§§topViewedAltINDEX§§§§topViewedDescriptionINDEX"] = $this->limit;
		# check (if we have a category) if the category exists in the database (if not: return 404)
		$this->pageExists($views);
		
		if ($this->pageFile != "404"){
			$index=0;
			foreach($views as $viewObject){
				$category = ucfirst($viewObject->category);
				$this->tagHash["topViewedCover$index"] = $this->getCover($viewObject->bookId, $viewObject->coverExtension);
				$this->tagHash["imgLink$index"] = $this->defaultScriptName . "?page=book&amp;id=" . $viewObject->bookId;
				$this->tagHash["topViewedAlt$index"] = str_replace("__title__", $viewObject->bookTitle, $this->messages["altText"]);
				$textBox = str_replace("__views__", $viewObject->views, str_replace("__title__", $viewObject->bookTitle, $topViewedBox));
				$textBox = str_replace("__authors__", $viewObject->authors, str_replace("__description__", $viewObject->shortDescription, $textBox));
				$editor = $viewObject->editor;
				if (!$editor){
					$editor = $this->messages["noEditor"];
				}											  # simply does nothing with a category
				$textBox = str_replace("__editor__", $editor, str_replace("__category__", $category, $textBox));
				$this->tagHash["topViewedDescription$index"] = $textBox;
				$index++;
			}
		}
		$this->prevNext($numBooks);
		return $this->render();
	}
	
	abstract public function getViewesAndBox();
	
	abstract public function pageExists($views);

	public function __destruct() {
		parent::__destruct();
	}
};

?>
